package com.omega.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.omega.dao.ItemDistributedDao;
import com.omega.entity.ItemDistributed;
import com.omega.service.ItemDistributedService;

@Service
public class ItemDistributedServiceImpl implements ItemDistributedService {

	@Autowired
	ItemDistributedDao itemDistributedDao;

	@Override
	@Transactional(rollbackFor = Exception.class)
	public List<ItemDistributed> loadAllItemsDistributed() {
		return itemDistributedDao.loadAllItemDistributed();
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public void addItemDistributed(ItemDistributed itemDistributed) {
		itemDistributedDao.addItemDistributed(itemDistributed);
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public ItemDistributed loadById(long itemDistributedId) {
		return itemDistributedDao.loadById(itemDistributedId);
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public void updateItemDistributed(ItemDistributed form) {
		ItemDistributed itemDistributedEntity = itemDistributedDao
				.loadById(form.getitemDistributedId());
		itemDistributedEntity.setBillNo(form.getBillNo());
		itemDistributedEntity.setDenomination(form.getDenomination());
		itemDistributedEntity.setGrandTotal(form.getGrandTotal());
		itemDistributedEntity.setItem(form.getItem());
		itemDistributedEntity.setMeasuringUnit(form.getMeasuringUnit());
		itemDistributedEntity.setNoOfUnits(form.getNoOfUnits());
		itemDistributedEntity.setPricePerUnit(form.getPricePerUnit());
		itemDistributedEntity.setRetailer(form.getRetailer());
		itemDistributedEntity.setTaxes(form.getTaxes());
		itemDistributedEntity.setTotalWithoutTax(form.getTotalWithoutTax());
		itemDistributedDao.updateItemDistributed(itemDistributedEntity);
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public void deleteItemDistributed(long itemDistributedId) {
		itemDistributedDao.deleteitemDistributed(itemDistributedId);
	}
}
